var pageNo = null;
var articlesSize = $("#articlesSize").val();
var totalPage = Math.ceil(parseInt(articlesSize) / 10);
//通过浏览器url截取文章类型
var locationUrl = window.document.location.href;
var lastFlag = locationUrl.lastIndexOf('/');
var aType = locationUrl.substring(lastFlag+1,locationUrl.length);

//分页按钮
$("#page").Page({
	totalPages : totalPage,//分页总数
	liNums : 7,//分页的数字按钮数(建议取奇数)
	activeClass : 'activP', //active 类样式定义
    hasFirstPage: true,//whether has first button
    hasLastPage: true,//whether has last button
    hasPrv: true,//whether has prev button
    hasNext: true,//whether has next button
	callBack : function(page){
		pageNo = page;
		articlesList();
	}
});

//文章列表
function articlesList(){
	$.ajax({
		url:g_requestContextPath + "/cms/articlesJs",
		type:"post",
		dataType:"json",
		async: false, 
		data:{
			"aType":aType,
			"pageNo":pageNo
		},
		success:function(data){
			console.log(data);
			totalPage = Math.ceil(parseInt(data.length) / 10);
			var aHtml = '';
			for (var i = 0; i < data.length; i++) {
				aHtml += '<li>';
				aHtml += '<a href="'+g_requestContextPath+'/cms/article/'+data[i].id+'">'+data[i].title+'</a>';
				aHtml += '<p class="u-time">'+new Date(data[i].createTime).format("yyyy-MM-dd")+'</p>';
				aHtml += '<p class="u-text">'+data[i].excerpt+'</p>';
				aHtml += '</li>';
			}
			$(".m-media").html(aHtml);
		}
	});
}